package cn.ljl.org.service.impl;


import cn.ljl.back.util.PageList;
import cn.ljl.org.domain.Department;
import cn.ljl.org.mapper.DepartmentMapper;
import cn.ljl.org.query.DepartmentQuery;
import cn.ljl.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.xml.ws.soap.Addressing;
import java.util.List;

/**
 * 业务实现类：部门
 */
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;


    @Override
    public List<Department> loadAll() {
        return departmentMapper.loadAll();
    }

    @Override
    public Department loadById(Long id) {
        return departmentMapper.loadById(id);
    }

    @Override
    @Transactional
    public void save(Department department) {
        departmentMapper.save(department);
    }

    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    @Transactional
    public void del(Long id) {
        departmentMapper.del(id);
    }

    @Override
    public PageList<Department> queryPage(DepartmentQuery departmentQuery) {
        //1.查询总数量 - 前端计算分页栏
        Integer totals = departmentMapper.queryCount(departmentQuery);
        if(totals==null){//没有数据
            return new PageList<>();
        }

        //2.查询当前页的分页数据 - 前端展示当前页的数据
        List<Department> data = departmentMapper.queryData(departmentQuery);

        return new PageList<>(totals,data);
    }
}
